package com.lill.sale.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lill.common.component.util.IdUtil;
import com.lill.product.model.ProductBaseModel;
import com.lill.product.service.IProductBaseService;
import com.lill.sale.dao.ISaleCustomerDao;
import com.lill.sale.model.SaleCustomerModel;
import com.lill.sale.service.ISaleCustomerService;

/**
 * 客户信息Service实现类
 *
 * @author lill
 * @date 2021-09-25 11:41:47
 */
@Service("saleCustomerService")
public class SaleCustomerServiceImpl implements ISaleCustomerService {
	
    @Autowired
    private ISaleCustomerDao saleCustomerDao;
    @Autowired
    private IProductBaseService productBaseService;

    public SaleCustomerModel queryObject(String id) {
    	SaleCustomerModel customerModel=saleCustomerDao.queryObject(id);
    	if(null!=customerModel&&StringUtils.isNotEmpty(customerModel.getProductId())){
    		ProductBaseModel productBase=productBaseService.queryObject(customerModel.getProductId());
    		if(null!=customerModel&&null!=productBase){
    			customerModel.setProductName(productBase.getAllName());
    		}
    	}
        return customerModel;
    }

    public List<SaleCustomerModel> queryList(Map<String, Object> map) {
    	List<SaleCustomerModel> customerList=saleCustomerDao.queryList(map);
//    	if(null!=customerList&&!customerList.isEmpty()){
//    		Map<String, String> carMap=new HashMap<String, String>();
//    		for (SaleCustomerModel saleCustomer : customerList) {
//				if(StringUtils.isNotEmpty(saleCustomer.getProductId())){
//					if(carMap.containsKey(saleCustomer.getProductId())){
//						saleCustomer.setProductName(carMap.get(saleCustomer.getProductId()));
//					}else{
//						ProductBaseModel productBase=productBaseService.queryObject(saleCustomer.getProductId());
//			    		if(null!=productBase){
//			    			saleCustomer.setProductName(productBase.getAllName());
//			    			carMap.put(saleCustomer.getProductId(), productBase.getAllName());
//			    		}
//					}
//				}
//			}
//    	}
        return customerList;
    }

    public int queryTotal(Map<String, Object> map) {
        return saleCustomerDao.queryTotal(map);
    }

    public int save(SaleCustomerModel saleCustomer) {
        saleCustomer.setId(IdUtil.createIdbyUUID());
        return saleCustomerDao.save(saleCustomer);
    }

    public int update(SaleCustomerModel saleCustomer) {
        return saleCustomerDao.update(saleCustomer);
    }

	public int deleteLogicByMap(Map<String, Object> map) {
		return saleCustomerDao.deleteLogicByMap(map);
	}
}
